home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / phigs / ptk.lha / ptk / source / demo / utiltest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  6.4 KB  |  236 lines

  1. /*----------------------------------------------------------------------------
  2.  
  3.   Module name: Utilities demo program.
  4.  
  5.   Author: Gareth Williams.
  6.  
  7.   Function: Demonstrates the PHIGS Debugger and PHIGS view editor.
  8.  
  9.   Modification history: (Version), (Date), (name), (Description).
  10.  
  11.   1.0, 30th October 1991, G. Williams, First Version.
  12.  
  13.   2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
  14.  
  15.  SunOS requirements: SunPHIGS 2.0, OpenWindows 3.0.
  16.  
  17. ----------------------------------------------------------------------------*/
  18.  
  19. #include <stdio.h>
  20. #include <math.h>
  21. #include <phigs.h>
  22. #include "ptk.h"
  23.  
  24. /* Operating system dependent code, UNIX/VMS pathnames */
  25. /* UNIX pathnames */
  26. #define LAMPSCRIPTNAME "../scripts/lamp.scr"
  27. #define CARDSCRIPTNAME "../scripts/postcard.scr"
  28. #define OPENWSNAME "../scripts/openws.scr"
  29.  
  30. /*
  31. #ifdef VMS
  32. #define LAMPSCRIPTNAME "[-.scripts]lamp.scr"
  33. #define CARDSCRIPTNAME "[-.scripts]postcard.scr"
  34. #endif
  35. */
  36.  
  37. static char *colwrd[] = 
  38.      {
  39.          "BLACK", "WHITE", "GREEN", 
  40.          "BLUE", "CYAN", "GREY", "RED" 
  41.      };
  42.  
  43. #define WS1 1
  44.  
  45. static Pfloat devx, devy, devz;
  46. static ptkboolean docolour = FALSE;
  47.  
  48. /*--------------------------------------------------------------------------*/
  49.  
  50. main()
  51. {
  52.   Pint wst;
  53.   Pint minid, maxid, lampid, white, black, green, grey, stid, stcom, lightblue;
  54.   Ppoint pos, size;
  55.   char ststr[20];
  56.   Plimit echoarea;
  57.   char commandstr[20], str[50];
  58.   Pint lencom, lenstr, err, textfont;
  59.   ptkboolean quit, useattrs;
  60.   Pview_rep3 viewrep;
  61.   Pint_list stids;
  62.   Pws_st_tables lens;
  63.  
  64.   /* Implementation dependent code, open PHIGS and workstation */
  65. #if SUN
  66.   printf("Opening SunPHIGS...\n");
  67.   popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
  68.  
  69.   /* open the workstation */
  70.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  71.  
  72.  
  73. /* create the workstation type (tool) 
  74.   wst = phigs_ws_type_create( phigs_ws_type_x_tool,
  75.     PHIGS_TOOL_LABEL, "SunPHIGS Tool Workstation",
  76.         PHIGS_COLOUR_MODE, PHIGS_INDEX_COLOUR,
  77.         PHIGS_X_BUF_MODE, PHIGS_BUF_DOUBLE_CMAP,
  78.         PHIGS_COLOUR_TABLE_SIZE, 8,
  79.     0);
  80.   if ( !wst ) 
  81.   {
  82.     pclose_phigs();
  83.     exit(1);
  84.   }
  85.  
  86.   popen_ws(WS1, (void *)NULL, wst);
  87.   {
  88.     Pws_st    ws_state;
  89.     
  90.     pinq_ws_st(&ws_state);
  91.     if (ws_state != PWS_ST_WSOP)
  92.       exit(3);
  93.   }
  94. */
  95. #endif
  96. #ifdef PEXSI
  97.   printf("Opening PEX-SI PHIGS...\n");
  98.   popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
  99.  
  100.   /* open the workstation */
  101.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  102. #endif
  103. #ifdef HP
  104.   printf("Opening HP PHIGS...\n");
  105.   popen_phigs(stderr, PDEF_MEM_SIZE);
  106.  
  107.   /* open the workstation */
  108.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  109. #endif
  110.  
  111.   ptk_inqmaxdevicecoords(WS1, &devx, &devy);
  112.   devz = 0.0;
  113.  
  114. #ifdef SUN
  115. #ifndef SUNMONO
  116.   docolour = TRUE;
  117. #endif
  118. #endif
  119. #ifdef HP
  120. #ifndef HPMONO
  121.   docolour = TRUE;
  122. #endif
  123. #endif
  124. #ifdef PEXSI
  125. #ifndef PEXSIMONO
  126.   docolour = TRUE;
  127. #endif
  128. #endif
  129.  
  130.    pset_disp_upd_st(WS1, PDEFER_WAIT, PMODE_NIVE); 
  131.    
  132.    /* initialise hashtables */
  133.    minid = 1;
  134.    maxid = 500;
  135.    ptk_inithashtables();
  136.    ptk_createhashtable("structureid", minid, maxid);
  137.    ptk_createhashtable("label", minid, maxid);
  138.    ptk_createhashtable("colourindex", 1, maxid);
  139.    ptk_createhashtable("viewindex", 1, maxid);
  140.    ptk_createhashtable("windowid", 1, maxid);
  141.    ptk_createhashtable("menuid", 1, maxid);
  142.    ptk_createhashtable("name", 1, maxid);
  143.    ptk_createhashtable("topologyid", 1, maxid);
  144.  
  145.    /* set colours */
  146.    if (docolour)
  147.    {
  148.      ptk_setupcolourtable(WS1, 7, colwrd);
  149.      green = ptk_stringtoint("colourindex", "green");
  150.      grey = ptk_stringtoint("colourindex", "grey");
  151.      white = ptk_stringtoint("colourindex", "white");
  152.      black = ptk_stringtoint("colourindex", "black");
  153.      lightblue = ptk_stringtoint("colourindex", "blue");
  154.    
  155.      /* Implementation dependent code, choose a nice font */
  156. #ifdef SUN
  157.      textfont = PFONT_TRIPLEX;
  158. #endif
  159. #ifndef SUN
  160.      textfont = 1;
  161. #endif
  162.      ptk_setbackgroundcolourind(WS1, grey);
  163.      ptk_setdebuggerattrs(textfont, textfont, grey, black, grey, green, 
  164.                           black, white, black, grey, black);
  165.      ptk_setvieweditorattrs(textfont, textfont, grey, black, grey, green, 
  166.                             black, white, black, grey, black);
  167.    }
  168.  
  169.    /* read scripts */
  170.    ptk_readphinterscript(LAMPSCRIPTNAME, NULL, NULL);
  171.    ptk_readphinterscript(CARDSCRIPTNAME, NULL, NULL);
  172.  
  173.    stid = ptk_stringtoint("structureid", "lamp");
  174.    stids.num_ints = 1;
  175.    stids.ints = &stid;
  176.  
  177.      /* select debugger/ view */
  178.  
  179.     quit = FALSE;
  180.     useattrs = TRUE;
  181.     do
  182.     {
  183.       pset_loc_mode(WS1, 1, POP_REQ, PSWITCH_ECHO);
  184.       pset_pick_mode(WS1, 1, POP_REQ, PSWITCH_ECHO);
  185.       echoarea = ptk_limit(0.0, devx, 0.0, devy * 0.1);
  186.       ptk_readstring(WS1, "debugger", "Input command (default = debugger) >", 
  187.                      &echoarea, 20, commandstr, &lencom);
  188.       if (strncmp(commandstr, "debugger", lencom) == 0)
  189.       {
  190.         ptk_readstring(WS1, "lamp", 
  191.                        "Input structure name (default = lamp) >", 
  192.                         &echoarea, 50, str, &lenstr);
  193.         stid = ptk_stringtoint("structureid", str);
  194.         printf("Demonstrating the PHIGS debugger module of the PHIGS Toolkit...\n");
  195.         ptk_debugger(WS1, stid);
  196.       }
  197.       else
  198.       if (strncmp(commandstr, "view", lencom) == 0)
  199.       {
  200.         ptk_readstring(WS1, "lamp", 
  201.                        "Input structure name (default = lamp) >", 
  202.                         &echoarea, 50, str, &lenstr);
  203.         printf("Demonstrating the PHIGS view editor module of the PHIGS Toolkit...\n");
  204.         stid = ptk_stringtoint("structureid", str);
  205.         ptk_vieweditor(WS1, &stids, &viewrep);
  206.       }
  207.       else if (strncmp(commandstr, "phinter", lencom) == 0)
  208.       {
  209.         ptk_callphinter();
  210.       }    
  211.       else if (strncmp(commandstr, "help", lencom) == 0)
  212.       {
  213.         printf("utiltest options\n");
  214.         printf("----------------\n");
  215.         printf("debugger - start up PHIGS debugger\n");
  216.         printf("view - start up PHIGS view editor\n");
  217.         printf("phinter - call phinter\n");
  218.         printf("quit - exit utiltest\n");
  219.       }    
  220.       else if (strncmp(commandstr, "quit", lencom) == 0)
  221.       {
  222.         quit = TRUE;
  223.       }    
  224.       else
  225.       {
  226.         printf("Command unknown\n");    
  227.       }
  228.       pupd_ws(WS1, PFLAG_PERFORM);
  229.     } while (quit == FALSE);
  230.  
  231.    pclose_ws(WS1);                          /* Close workstation. */
  232.    pclose_phigs();                          /* Close PHIGS. */
  233. }
  234.  
  235. /*--------------------------------------------------------------------------*/
  236.